import React, {Component} from "react";
import {observer, inject} from "mobx-react";
import {withRouter} from "react-router-dom";
import {ActivityIndicator} from "weaver-mobile";
import {Form} from "weaver-mobile-page";
import {getRouteParams} from "../../util";

@inject("taskFormStore")
@withRouter
@observer
export default class TaskForm extends Component {
    componentWillMount() {
        this.Init(this.props)
    }

    componentWillReceiveProps(nextProps, nextContext) {
        this.Init(nextProps)
    }

    Init = (props) => {
        const {taskFormStore} = props;
        const {taskid, viewtype} = getRouteParams(props);
        taskFormStore.init(taskid, viewtype);
    };

    render() {
        const {taskFormStore: {taskForm, isLoading}} = this.props;
        return (<div>
            {isLoading ?
                (<div className='loading'><ActivityIndicator animating size='large'/></div>) :
                <Form store={taskForm}/>
            }
        </div>)
    }
}
